package com.shaoshaohuo.app.framework.log;

import android.util.Log;

import com.shaoshaohuo.app.net.HttpConfig;

/**
 * 系统统一日志工具，替代系统自带的Log
 * @author YinSF
 * @createDate 2015-11-17
 */
public class LogUtil {
	private static final String LOG_TAG = "LogUtil";
	private static final int VERBOSE = 1;
	private static final int DEBUG = 2;
	private static final int INFO = 3;
	private static final int WARN = 4;
	private static final int ERROR = 5;
	
	/**
	 * 设置日志的级别
	 */
	private static int CURRENT_LEVEL = ERROR;

	static  {
		switch (HttpConfig.serverEnvironment) {
			case DEVELOPMENT:
				CURRENT_LEVEL = DEBUG;
				break;
			case TEST:
				CURRENT_LEVEL = DEBUG;
				break;
			case ONLINE:
				CURRENT_LEVEL = INFO;
				break;
		}
	}
	
	public static void v(String tag, String msg) {
		if (CURRENT_LEVEL <= VERBOSE) {
			Log.v(tag, msg);
		}
	}
	public static void d(String tag, String msg) {
		if (CURRENT_LEVEL <= DEBUG) {
			Log.d(tag, msg);
		}
	}
	public static void i(String tag, String msg) {
		if (CURRENT_LEVEL <= INFO) {
			Log.i(tag, msg);
		}
	}
	public static void w(String tag, String msg) {
		if (CURRENT_LEVEL <= WARN) {
			Log.w(tag, msg);
		}
	}
	public static void e(String tag, String msg) {
		if (CURRENT_LEVEL <= ERROR) {
			Log.e(tag, msg);
		}
	}
	
	/** 带异常 */
	public static void v(String tag, String msg, Throwable tr) {
		if (CURRENT_LEVEL <= VERBOSE) {
			Log.v(tag, msg, tr);
		}
	}
	public static void d(String tag, String msg, Throwable tr) {
		if (CURRENT_LEVEL <= DEBUG) {
			Log.d(tag, msg, tr);
		}
	}
	public static void i(String tag, String msg, Throwable tr) {
		if (CURRENT_LEVEL <= INFO) {
			Log.i(tag, msg, tr);
		}
	}
	public static void w(String tag, String msg, Throwable tr) {
		if (CURRENT_LEVEL <= WARN) {
			Log.w(tag, msg, tr);
		}
	}
	public static void e(String tag, String msg, Throwable tr) {
		if (CURRENT_LEVEL <= ERROR) {
			Log.e(tag, msg, tr);
		}
	}
}
